<?php
require_once 'system/core/Model.php';
require_once 'application/models/Notice.php';

class Notice_Model extends CI_Model{
	function __construct(){
		parent::__construct();
	}
	
	var $_notice;
	
	function get_notice_model($ID, $senderID, $type, $title, $content, $time){
		return $this->_notice = new Notice($ID, $senderID, $type, $title, $content, $time);
	}
	
	function insert_notice($senderID, $type, $title, $content, $time){
		$data = $this->get_notice_model(1, $senderID, $type, $title, $content, $time);
		unset($data->ID);
		return $this->db->insert("notice", $data);
	}
	
	function delete_notice($ID){
		$this->db->where("ID", $ID);
		$this->db->delete("notice");
	}
	
	function update_notice($ID, $senderID, $type, $title, $content, $time){
		$data = $this->get_notice_model($ID, $senderID, $type, $title, $content, $time);
		$this->db->where("ID", $ID);
		$this->db->update("notice", $data);
	}
	
	function query_notice($limit, $offset){
		$this->db->order_by("time", "desc");
		return $this->db->get("notice", $limit, ($offset-1)*$limit);
	}
	
	function query_notice_by_ID($ID){
		$this->db->where("ID", $ID);
		return $this->db->get("notice");
	}
	
	function query_notice_by_senderID($senderID){
		$this->db->where("senderID", $senderID);
		return $this->db->get("notice");
	}
	
	function getALL(){
		return $this->db->get("notice");
	}
}
?>